home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / inc / msdostcp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  4.3 KB  |  159 lines

  1. #ifdef MSDOS
  2. #ifndef __MSDOSTCP_H
  3. #define __MSDOSTCP_H
  4. /*
  5.  *    NOTE:    BIG HACK on WATTCP that you will have to do.
  6.  *    Take care to change the wattcp *.c and *.h files so that the tokens
  7.  *        #include<tcp.h>
  8.  *        getsockname
  9.  *        sockaddr
  10.  *        sockaddr_in
  11.  *        in_addr
  12.  *    are now
  13.  *        #include"c:\wattcp\include\tcp.h" or whatever the path is
  14.  *        hack_getsockname
  15.  *        hack_sockaddr
  16.  *        hack_in_addr
  17.  *
  18.  *    By using #define statements at the start of important wattcp headers,
  19.  *    it should be very easy to do.
  20.  *    This is to avoid name clashes only with tokens that I will code
  21.  *    for better WWW and Berkeley socket compatibility.
  22.  *    As for the header file tcp.h, there is one in WWW and Wattcp.  To
  23.  *    avoid confusion, make sure the WWW\LIBRARY\IMPLEMEN directory is
  24.  *    first in the include path search, and in all the wattcp code,
  25.  *    specify the full path for the tcp.h file as above.
  26.  */
  27.  
  28. /*
  29.  *     Wattcp fails to implement sockets in a directly compatible manner.
  30.  *    Must define some common things used in WWW and implement functions
  31.  *    to do the same thing as open, socket, bind, etc... in unix.
  32.  *    The compatible(?) implementation can be found in msdostcp.c
  33.  */
  34. #include<time.h>
  35. #include<sys\stat.h>
  36. #include"..\wattcp\include\tcp.h"
  37.  
  38. /*
  39.  *    Range of ports assignable by the system.
  40.  */
  41. #define MIN_TCP_PORT    1024
  42. #define MAX_TCP_PORT    5999
  43.  
  44. /*
  45.  *     Undefine those things that clash from wattcp.
  46.  *    We will have to call wattcp code that uses these things by using
  47.  *    the prefix hack_, except sockaddr_in, which we will substitute
  48.  *    hack_sockaddr directly.  See above.
  49.  */
  50. #undef getsockname
  51. #undef sockaddr
  52. #undef sockaddr_in
  53. #undef in_addr
  54.  
  55. #undef NETREAD
  56. #undef NETWRITE
  57. #undef NETCLOSE
  58. #define NETREAD(s, b, l) s_read(s, b, l)
  59. #define NETWRITE(s, b, l) s_write(s, b, l)
  60. #define NETCLOSE(s) s_close(s)
  61.  
  62. #define SOCK_STREAM 1
  63. #define AF_INET 2
  64. #define IPPROTO_TCP 6
  65. #define INADDR_ANY (unsigned long)0x00000000
  66.  
  67. struct hostent    {
  68.     char *h_name;
  69.     char **h_aliases;
  70.     int h_addrtype;
  71.     int h_length;
  72.     char **h_addr_list;
  73. };
  74. #define h_addr h_addr_list[0]
  75.  
  76. struct servent {
  77.     char *s_name;
  78.     char **s_aliases;
  79.     int s_port;
  80.     char *s_proto;
  81. };
  82.  
  83. struct sockaddr    {
  84.     unsigned short sa_family;
  85.     char sa_data[14];
  86. };
  87.  
  88. struct in_addr    {
  89.     unsigned long s_addr;
  90. };
  91.  
  92. struct sockaddr_in    {
  93.     short sin_family;
  94.     unsigned short sin_port;
  95.     struct in_addr sin_addr;
  96.     char sin_zero[8];
  97. };
  98.  
  99. int socket(int family, int type, int protocol);
  100. int connect(int sockfd, struct sockaddr *servaddr, int addrlen);
  101. struct hostent *gethostbyname(char *hostname);
  102. struct servent *getservbyname(char *servname, char *protname);
  103. int s_read(int fildes, char *buff, unsigned int nbytes);
  104. int s_write(int fildes, char *buff, unsigned int nbytes);
  105. int s_close(int fildes);
  106. int accept(int sockfd, struct sockaddr *peer, int *addrlen);
  107. int bind(int sockfd, struct sockaddr *myaddr, int addrlen);
  108. int listen(int sockfd, int backlog);
  109.  
  110. /*
  111.  *     Functions may not be implemented yet.
  112.  *    Check msdostcp.c
  113.  */
  114. int getsockname(int sockfd, struct sockaddr *peer, int *addrlen);
  115.  
  116. /*
  117.  *    Socket structure used in msdostcp
  118.  */
  119. typedef struct socket_info_tag    {
  120.     int i_family, i_type, i_protocol;
  121.     void *vp_sockfd;
  122.     unsigned short int usi_EOF, usi_IO, usi_OPEN;
  123.     unsigned long int uli_read, uli_written;
  124.     unsigned long int uli_bindmyaddr;
  125.     unsigned short int usi_bindmyport;
  126.     unsigned char uc_used;
  127.     signed short int ssi_backlog;
  128.     signed short int *ssip_backlogfd;
  129. }
  130. socket_info;
  131.  
  132. /*
  133.  *    MAXSOCKETS thought to be the limit of open sockets with WATTCP.
  134.  *    Global variable for outside routines to recognize which socket
  135.  *    is being referenced and the table to use the reference in.  -1 if
  136.  *    invalid or not referencing anything.
  137.  */
  138. #define MAXSOCKETS 16
  139. extern signed short int ssi_sockfd;
  140. extern socket_info sock_table[MAXSOCKETS];
  141.  
  142. #ifdef WWW
  143. /*
  144.  *     The following is to help in converting the WWW library to dos.
  145.  *    The code can still be found in msdostcp.c although it has nothing
  146.  *    to do with Berkeley sockets so to speak.
  147.  */
  148. char *crypt(char *key, char *salt);
  149.  
  150. /*
  151.  *    The following is a function to be passed to wattcp's sock_yield
  152.  *    function.
  153.  *    Application specific;  source defined elsewhere.
  154.  */
  155. extern void yield(void);
  156.  
  157. #endif /* WWW */
  158. #endif /* __MSDOSTCP_H */
  159. #endif /* MSDOS */